<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/base/base.jsp"%>
<%@ include file="/base/database.jsp"%>
<%

	 String usertype=request.getParameter("usertype");


	 if("0".equals(usertype)){
	

	 String loginNo = request.getParameter("loginNo");
	 String password =request.getParameter("password");

	 boolean flag=false;
	 Connection conn=null;
	 PreparedStatement pstmt=null;
	 ResultSet rs =null;
	 String targetURL="/page/manager/managerindex.jsp";
	 try{

	  	conn=getConn();
	  	String sql="select * from sys_manager where loginNo=? and password=?";
	  	pstmt=conn.prepareStatement(sql);

	  	int index=1;
	  	pstmt.setNString(index++, loginNo);
	  	pstmt.setNString(index++, password);

	  	rs=pstmt.executeQuery();
	  	flag=rs.next();
	   }catch(SQLException e){
	     e.printStackTrace();
	   }finally{
	     close(rs, pstmt, conn);
	   }

	  if(flag){
		
		session.setAttribute("loginNo", loginNo);
	    process(request, response, "/page/manager/managerindex.jsp");
	  }else{
	    process(request, response, "/login.jsp");
	  }
	 
	
}

if("1".equals(usertype)){

	String loginNo=request.getParameter("loginNo");
	String password=request.getParameter("password");
	
	boolean flag=false;
	Connection conn=null;
	PreparedStatement pstmt=null;
	ResultSet rs=null;
	
	String targetURL="/page/instructor/instructorindex.jsp";
	
	try{
		conn=getConn();
		String sql="select * from sys_instructorlogin where loginNo=? and password=?";
		pstmt=conn.prepareStatement(sql);
		
		int index=1;
		pstmt.setNString(index++,loginNo);
		pstmt.setNString(index++,password);
		
		rs=pstmt.executeQuery();
		
		flag=rs.next();
		
	}catch(SQLException e){
		e.printStackTrace();
	}finally{
		close(rs,pstmt,conn);
	}
	
	if(flag){
		
		session.setAttribute("loginNo",loginNo);
	
		process(request,response,"/page/instructor/instructorindex.jsp");
	}else{
		process(request,response,"/login.jsp");
	}
	
}

if("2".equals(usertype)){
	
	 String loginNo = request.getParameter("loginNo");
	 String password =request.getParameter("password");
	
	 boolean flag=false;
	 Connection conn=null;
	 PreparedStatement pstmt=null;
	 ResultSet rs =null;
	 String targetURL="/page/student/studentindex.jsp";
	 try{
	 
	  	conn=getConn();
	  	String sql="select * from sys_studentlogin where loginNo=? and password=?";
	  	pstmt=conn.prepareStatement(sql);
	
	  	int index=1;
	  	pstmt.setNString(index++, loginNo);
	  	pstmt.setNString(index++, password);
	
	  	rs=pstmt.executeQuery();
	  	flag=rs.next();
	   }catch(SQLException e){
	     e.printStackTrace();
	   }finally{
	     close(rs, pstmt, conn);
	   }

	  if(flag){
	
		session.setAttribute("loginNo", loginNo);
	    process(request, response, "/page/student/studentindex.jsp");
	  }else{
	    process(request, response, "/login.jsp");
	  }
	
}
%>